package com.fivefox.approval.service.impl;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.fivefox.approval.domain.ApprovalInstancesData;
import com.fivefox.approval.service.ApprovalService;
import com.fivefox.common.authentication.AccessCredentialsTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: 李任起
 * @description: 类描述
 * @createDate: 2024-02-27 18:55
 */
@Service
@Slf4j
public class ApprovalServiceImpl implements ApprovalService {

    @Resource
    private AccessCredentialsTool accessCredentialsTool;

    @Override
    public <T> ApprovalInstancesData<T> queryApprovalDetailByInstanceId(String instanceId, T approvalForm) {
        String resultStr = HttpRequest.get("https://open.feishu.cn/open-apis/approval/v4/instances/" + instanceId)
                .header("Authorization", "Bearer " + accessCredentialsTool.getAppAccessToken())
                .execute().body();
//        log.info("接口【获取单个审批实例详情】返回结果：" + resultStr + "\n");

        JSONArray baseRes = JSONUtil.parseArray(resultStr);


//        log.info("json转换结果：" + JSONUtil.parseObj(baseRes.getData()));
        return null;
    }
}
